package serializer

import "strconv"

type errorCode int

// 通用错误码
const (
	CodeOk                 errorCode = 200
	CodeUnknownError       errorCode = -1
	CodeParamError         errorCode = 10001
	CodeTokenNotFoundError errorCode = 10002
	CodeTokenExpiredError  errorCode = 10003
	//上传文件错误
	CodeUploadErrot errorCode = 10004
	//邮箱发送错误
	CodeSendEmailError errorCode = 10005
	//无结果
	CodeNoResult errorCode = 10006

	//redis操作失败
	RedisError errorCode = 30001

	//上传数据为空
	CodeIsNullOfUpContext errorCode = 30002

	//当前日期已经打卡
	CodeIsDaka errorCode = 40001
	//打卡失败
	CodeDakaError errorCode = 40002
	//今日未打卡
	CodeIsNotDakaToday errorCode = 40003
	//积分不足
	CodeIsNoAmple errorCode = 40004
)

// 用户相关的错误
const (
	// 注册错误
	CodeUserExistError       errorCode = 20001
	CodePasswordConfirmError errorCode = 20002
	CodeEmailExistError      errorCode = 20003

	// 登录错误
	CodeUserNotExistError errorCode = 21001
	CodePasswordError     errorCode = 21002

	//修改密码错误
	CodeChangePasswordError errorCode = 21003
)

// 错误码与描述信息map
var msgMap = map[errorCode]string{
	CodeOk:                 "ok",
	CodeUnknownError:       "未知错误",
	CodeParamError:         "请求参数错误",
	CodeTokenNotFoundError: "需要权限",
	CodeTokenExpiredError:  "token过期或不正确",

	CodeUserExistError:       "注册失败，用户已存在",
	CodePasswordConfirmError: "注册失败，两次输入密码不一致",
	CodeEmailExistError:      "该邮箱已经存在",

	CodeUserNotExistError: "登录失败，用户名不存在",
	CodePasswordError:     "登录失败，密码错误",

	CodeUploadErrot:    "文件上传失败",
	CodeSendEmailError: "邮件发送失败",

	CodeChangePasswordError: "修改密码错误",

	RedisError: "redis操作失败",

	CodeNoResult: "无结果",

	CodeIsNullOfUpContext: "上传数据为空",

	CodeIsDaka:         "当前日期已经签到",
	CodeDakaError:      "签到失败",
	CodeIsNotDakaToday: "今日还未签到",
	CodeIsNoAmple:      "积分不足",
}

// 根据错误码得到对应说明
func GetErrorMsg(code errorCode) string {
	msg, ok := msgMap[code]
	if !ok {
		msg = "未知错误，错误码：" + strconv.Itoa(int(code))
	}
	return msg
}
